package com.demo.feign.controller;

import com.demo.feign.service.FeignService;
import com.demo.feign.service.FeignService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/feign")
@EnableCaching
public class FeignController {

    @Autowired
    private FeignService feignService;

    @Autowired
    private FeignService2 feignService2;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * feign 调用常规路径接口
     * */
    @RequestMapping("/feign-address")
    public void test(){
        feignService.test();
    }

    /**
     * feign 调用服务接口
     * */
    @RequestMapping("feign-service")
    public void test1(){
        int i = 10;
        feignService2.test();
    }

    /**
     * template 调用常规路径接口
     * */
    @RequestMapping("/template-address")
    public void test3(){
        restTemplate.getForEntity("http://localhost:8081/nacos-discovery/discovery/test", String.class);
    }

    /**
     * template 调用服务接口
     * */
    @RequestMapping("/template-service")
    public void test4(){
        restTemplate.getForEntity("http://nacos-discovery/nacos-discovery/discovery/test", String.class);
    }

}
